package com.taxi.controller;


import com.taxi.dto.OrderDetailInfo;
import com.taxi.dto.OrderInfo;
import com.taxi.dto.PriceRule;
import com.taxi.request.OrderRequest;
import com.taxi.result.Result;
import com.taxi.service.IOrderInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

/**
 * @author aniu
 * @since 2023-10-03
 */
@RestController
@RequestMapping("/order")
public class OrderInfoController {

    @Autowired
    private IOrderInfoService orderInfoService;

    @ApiOperation("/创建订单/下单")
    @PostMapping("/add")
    public Result add(@RequestBody OrderRequest orderRequest){
//        HttpServletRequest request=null;
//        String deviceCode = request.getHeader("deviceCode");
//        orderRequest.setDeviceCode(deviceCode);
        return orderInfoService.add(orderRequest);
    }

    /**
     * 订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/detail")
    public Result<OrderInfo> detail(Long orderId){
        return orderInfoService.detail(orderId);
    }

    @ApiOperation("去接乘客")
    @PostMapping("/to-pick-up-passenger")
    public Result<OrderInfo> toPickUpPassenger(@RequestBody OrderRequest orderRequest){
        return orderInfoService.toPickUpPassenger(orderRequest);
    }

    @ApiOperation("到达乘客目的地")
    @PostMapping("/arrived-departure")
    public Result<OrderInfo> arrivedDeparture(@RequestBody OrderRequest orderRequest){
        return orderInfoService.arrivedDeparture(orderRequest);
    }

    @ApiOperation("乘客上车,司机开始行程")
    @PostMapping("/pick-up-passenger")
    public Result<OrderInfo> pickUpPassenger(@RequestBody OrderRequest orderRequest){
        return orderInfoService.pickUpPassenger(orderRequest);
    }

    @ApiOperation("乘客到达目的地,行程终止")
    @PostMapping("/passenger-getoff")
    public Result<OrderInfo> passengerGetOff(@RequestBody OrderRequest orderRequest){
        return orderInfoService.passengerGetOff(orderRequest);
    }

    @ApiOperation("司机发起收款")
    @PostMapping("/push-pay-info")
    public Result pushPayInfo(@RequestBody OrderRequest orderRequest){
        return orderInfoService.pushPayInfo(orderRequest);
    }

    @ApiOperation("支付完成")
    @PostMapping("/pay")
    public Result pay(@RequestBody OrderRequest orderRequest){
        return orderInfoService.pay(orderRequest);
    }

    @ApiOperation("订单取消")
    @PostMapping("/cancel")
    public Result cancel(@RequestParam Long orderId,@RequestParam String identity){
        return orderInfoService.cancel(orderId,identity);
    }

    /**
     * 判断当前用户有无正在进行中的订单
     * @param phone
     * @param identity
     * @return
     */
    @GetMapping("/current/{phone}/{identity}")
    public Result<OrderInfo> current(@PathVariable String phone ,@PathVariable String identity){
        return orderInfoService.current(phone , identity);
    }

    /**
     * 获取正在行程中的订单详情
     * @param orderId
     * @return
     */
    @GetMapping("/current-order-detail")
    public Result<OrderDetailInfo> currentOrderDetail(@RequestParam Long orderId){
        return orderInfoService.currentOrderDetail(orderId);
    }


    /**
     * 获取用户所有订单
     * @param phone
     * @param identity
     * @return
     */
    @GetMapping("/get-all-orders/{phone}/{identity}")
    public Result<ArrayList<OrderInfo>> getAllOrders(@PathVariable String phone , @PathVariable String identity){
        return orderInfoService.getAllOrders(phone,identity);
    }

    /**
     * 获取订单列表
     * @param page
     * @param limit
     * @param address
     * @param phone
     * @return
     */
    @GetMapping("/get-order-list")
    public Result getOrderList(@RequestParam int page, @RequestParam int limit, @RequestParam(required = false) String address, @RequestParam(required = false) String phone){
        return orderInfoService.getAllOrderList(page,limit,address,phone);
    }

    @PostMapping("/update")
    public Result updateOrder(@RequestBody OrderInfo orderInfo){
        return orderInfoService.updateOrder(orderInfo);
    }
}
